package com.netintech.project.system.word.service.impl;

import com.netintech.common.utils.text.Convert;
import com.netintech.project.system.word.domain.SensitiveWord;
import com.netintech.project.system.word.mapper.SensitiveWordMapper;
import com.netintech.project.system.word.service.ISensitiveWordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 敏感词Service业务层处理
 *
 * @author admin
 * createTime 2020-08-25
 * lastModify admin
 * lastModifyTime 2020-08-25
 * group 电子政务小组
 */
@Service
public class SensitiveWordServiceImpl implements ISensitiveWordService
{
    @Autowired
    private SensitiveWordMapper sensitiveWordMapper;

    /**
     * 查询敏感词
     * 
     * @param sensitiveWordId 敏感词ID
     * @return 敏感词
     */
    @Override
    public SensitiveWord selectSensitiveWordById(Long sensitiveWordId)
    {
        return sensitiveWordMapper.selectSensitiveWordById(sensitiveWordId);
    }

    /**
     * 查询敏感词列表
     * 
     * @param sensitiveWord 敏感词
     * @return 敏感词
     */
    @Override
    public List<SensitiveWord> selectSensitiveWordList(SensitiveWord sensitiveWord)
    {
        return sensitiveWordMapper.selectSensitiveWordList(sensitiveWord);
    }

    /**
     * 新增敏感词
     * 
     * @param sensitiveWord 敏感词
     * @return 结果
     */
    @Override
    public int insertSensitiveWord(SensitiveWord sensitiveWord)
    {
        int a = sensitiveWordMapper.insertSensitiveWord(sensitiveWord);
        if(a > 0){
            SensitiveWordFilterServiceImpl.addSensitiveWordToHashMap(sensitiveWordMapper.keyWordSet());
        }
        return a;
    }

    /**
     * 修改敏感词
     * 
     * @param sensitiveWord 敏感词
     * @return 结果
     */
    @Override
    public int updateSensitiveWord(SensitiveWord sensitiveWord)
    {
        int a = sensitiveWordMapper.updateSensitiveWord(sensitiveWord);
        if(a > 0){
            SensitiveWordFilterServiceImpl.addSensitiveWordToHashMap(sensitiveWordMapper.keyWordSet());
        }
        return a;
    }

    /**
     * 删除敏感词对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteSensitiveWordByIds(String ids)
    {
        int a = sensitiveWordMapper.deleteSensitiveWordByIds(Convert.toStrArray(ids));
        if(a > 0){
            SensitiveWordFilterServiceImpl.addSensitiveWordToHashMap(sensitiveWordMapper.keyWordSet());
        }
        return a;
    }

    /**
     * 删除敏感词信息
     * 
     * @param sensitiveWordId 敏感词ID
     * @return 结果
     */
    public int deleteSensitiveWordById(Long sensitiveWordId)
    {
        int a = sensitiveWordMapper.deleteSensitiveWordById(sensitiveWordId);
        if(a > 0){
            SensitiveWordFilterServiceImpl.addSensitiveWordToHashMap(sensitiveWordMapper.keyWordSet());
        }
        return a;
    }
}
